package sms

import (
	"errors"
	"longmen/server/pkg/db/redis/cache"
	"strings"
)

func New() (SMS, error) {
	configPri := cache.GetConfigPri()
	if configPri == nil {
		return nil, errors.New("系统配置读取失败")
	}
	switch strings.ToLower(configPri.SmsSelecter) {
	case "":
		return empty{}, nil
	case "aliyun":
		return newAli()
	case "qcloud":
		return newQcloud()
	case "ihuyi":
		return newOtp()
	default:
		return newQcloud()
	}
}

type SMS interface {
	Name() string
	SendCode(areaCode string, phoneNumber string, verifyCode string) error
}

type empty struct{}

func (e empty) Name() string {
	return "empty-sms"
}

func (e empty) SendCode(areaCode string, phoneNumber string, verifyCode string) error {
	return nil
}
